package com.ztspeech.vad;


import org.dragonnova.meetingapp.utils.LogUtil;

//TODO 包名路径不能改，只能是com.ztspeech.vad
public class VadJni {
	static {
		try {
			System.loadLibrary("ztvad");
		}catch (Exception e) {
			LogUtil.e("Vad", e.getMessage());
		}
	}
	
	public static final int VD_MODE_DNN = 0;
	public static final int VD_MODE_ENERGY = 1;
	public static final int VD_MODE_DNNENERGY = 2;
	public static final int VD_MODE_WEBRTC = 3;

	public static native long newVad(int sampleRate, int frameLenMs, int mode);
	public static native boolean resetVad(long hVad);
	public static native boolean restartVad(long hVad);
	public static native boolean delVad(long hVad);

	public static final int VD_PARAM_ESTIFRAMENUM = 11;
	public static final int VD_PARAM_MINENERGY = 12;
	public static final int VD_PARAM_MAXENERGY = 13;
	public static final int VD_PARAM_WORKMODE = 14;
	public static final int VD_PARAM_WEBRTCMODE = 15;
	public static final int VD_PARAM_CTXFRAMENUM = 16;
	
	public static native int setIntParam(long hVad, int param, int val);
	public static native int setFloatParam(long hVad, int param, float val);
	
	public static native boolean inputWave(long hVad, byte[] waveData, int offset, int frameNum, boolean isEnd);
	public static native boolean inputFloatWave(long hVad, float[] waveData, int offset, int frameNum, boolean isEnd);
	public static native int freeze(long hVad, int isFreeze);
	public static native int getMaxFrame(long hVad);
	public static native float getFrameProb(long hVad, int frame, int dim);

	
	public static native long vdNewVad(int mode);
	public static native boolean vdResetVad(long hVad);
	public static native boolean vdRestartVad(long hVad);
	public static native boolean vdDelVad(long hVad);

	public static final int VD_PARAM_PREFRAMENUM = 1;
	public static final int VD_PARAM_MINVOCFRAMENUM = 2;
	public static final int VD_PARAM_MINVOCRATIO = 5;
	public static final int VD_PARAM_MINSPEECHFRAMENUM = 6;
	public static final int VD_PARAM_MINSILFRAMENUM = 3;
	public static final int VD_PARAM_MINSILRATIO = 4;

	public static native int vdSetIntParam(long hVad, int param, int val);
	public static native int vdSetFloatParam(long hVad, int param, float val);

	public static native boolean vdInputWave(long hVad, byte[] waveData, int offset, int length, boolean isEnd);
	public static native boolean vdInputFloatWave(long hVad, float[] waveData, int offset, int length, boolean isEnd);
	public static native int vdGetOffsetFrame(long hVad);
	public static native int vdGetVoiceStartFrame(long hVad);
	public static native int vdGetVoiceStopFrame(long hVad);
	public static native int vdGetVoiceFrameNum(long hVad);
	public static native byte[] vdGetVoice(long hVad, int startFrame, int frameNum);
	public static native float[] vdGetFloatVoice(long hVad, int startFrame, int frameNum);
}
